package pers.chao.tool.infrastructure;

import org.springframework.util.StringUtils;

/**
 * Description: 默认值工具
 *
 * @author W.Chao
 * @date 2021/1/17 1:19
 **/
public final class DefaultValue {
	public static <R, T> R get(T obj, R value, R defaultValue) {
		return obj == null || value == null ? defaultValue : value;
	}

	public static <R> R get(R value, R defaultValue) {
		if (value instanceof String){
			String v = (String) value;
			return StringUtils.isEmpty(v) ? defaultValue : value;
		}
		return value == null ? defaultValue : value;
	}
}
